package org.example.hansp.array_.arraydemo;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayReduce {
    public static void main(String[] args) {
        int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        Scanner sc = new Scanner(System.in);

      /*  do {
           *//* int[] arr=new int[a.length-1];
            for (int i = 0; i < a.length-1; i++) {
                arr[i]=a[i];
            }*//*
            System.out.println("当前数组为： ");
            for (int i : a) {
                System.out.print(i+" ");
            }
            System.out.println("是否继续缩减 y/n");
            char choose=sc.next().charAt(0);
            a = Arrays.copyOf(a, a.length - 1);
            if(a.length==1){
                System.out.println("不能继续缩减");
                break;
            }
            if (choose == 'n') {
                break;
            }
        } while (true);
        for (int i : a) {
            System.out.print(i+" ");
        }*/
        reduceArray(a);

    }
    /*public static void reduceArray(int[] a,int length) {
        printArray(a, length);
      if (length == 1){
          return;
      }
      reduceArray(a,length-1);
    }*/
    public static void reduceArray(int[] a) {
        // 打印当前数组
        printArray(a, a.length);

        // 递归终止条件
        if (a.length == 1) {
            return;
        }

        // 复制数组并减少长度
        a = Arrays.copyOf(a, a.length - 1);

        // 递归调用
        reduceArray(a);
    }
//打印数组
    public static void printArray(int[] arr, int length) {
        System.out.print("[");
        for (int i = 0; i < length; i++) {
            System.out.print(arr[i]);
            if (i < length - 1) {
                System.out.print(", ");
            }
        }
        System.out.println("]");
    }
}
